package net.hn.hnms.biz.project.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.project.domain.MechanicalLedger;
import net.hn.hnms.biz.project.request.MechanicalLedgerReq;
import net.hn.hnms.biz.project.service.MechanicalLedgerService;
import net.hn.hnms.biz.project.vo.MechanicalLedgerVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "机械设备台账", tags = {"机械设备管理"})
@RestController
@RequestMapping("/project/mechanicalLedger")
public class MechanicalLedgerController extends BaseController {


    @Autowired
    private MechanicalLedgerService mechanicalLedgerService;

    @ApiOperation("机械设备列表")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<MechanicalLedgerVo>> page(MechanicalLedgerReq accidentInfoReq, PageQuery pageQuery) {
        return R.ok(mechanicalLedgerService.selectPageList(accidentInfoReq, pageQuery));
    }

    @ApiOperation("新增机械设备信息")
//    @SaCheckPermission("project:accident:add")
    @PostMapping("/add")
    @Log(title = "新增机械设备信息", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody MechanicalLedgerReq accidentInfoReq) {
        return toAjax(mechanicalLedgerService.insert(accidentInfoReq));
    }


    @ApiOperation("删除机械设备信息")
//    @SaCheckPermission("project:accident:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除机械设备信息", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        mechanicalLedgerService.updateDeleteByIds(idList);
        return R.ok();
    }


    @ApiOperation("更新机械设备信息")
//    @SaCheckPermission("project:accident:update")
    @PostMapping("/update")
    @Log(title = "更新机械设备信息", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody MechanicalLedgerReq contractInfoReq) {
        mechanicalLedgerService.updateById(contractInfoReq);
        return R.ok();
    }

    @ApiOperation("机械设备详情")
    @GetMapping("/{id}")
    public R<MechanicalLedger> detail(@PathVariable("id") String id) {
        return R.ok(mechanicalLedgerService.selectDetailById(id));
    }
}
